package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺管理")
public class ShopController {

    private final static String shop = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 修改店铺状态
     * @param status 1营业中，0打烊
     * @return
     */
    @ApiOperation("修改店铺状态")
    @PutMapping("{status}")
    public Result changeStatues(@PathVariable Integer status) {
        log.info("修改店铺状态:{}", status == 1 ? "营业中" : "打烊");
        // 修改店铺状态
        redisTemplate.opsForValue().set(shop, status);
        return Result.success();
    }

    /**
     * 查询店铺状态
     * @return
     */
    @GetMapping("status")
    @ApiOperation("查询店铺状态")
    public Result<Integer> status() {
        Integer status = (Integer) redisTemplate.opsForValue().get(shop);
        log.info("查询店铺状态:{}", status == 1 ? "营业中" : "打烊");
        return Result.success(status);
    }

}
